from django.db import models
from django.contrib.auth.models import User


class BlogRecord(models.Model):
    title = models.CharField(max_length=64)
    text = models.TextField()

    cdate = models.DateTimeField(auto_now_add=True)
    edate = models.DateTimeField(auto_now=True)

    author = models.ForeignKey(User)
    tags = models.TextField()

    published = models.BooleanField(default=True)

    def get_short_text(self):
        return ' '.join(self.text.split(' ')[:57])

    def get_text(self):
        return self.text

    def contains_tag(self, tag):
        return tag in self.tags


    @classmethod
    def get_to_show(BlogRecord):
        return BlogRecord.objects.filter(published=True)
